import cv2,numpy
import time
import all_socket
import struct
import numpy as np

"""
def camera_send():

  cap = cv2.VideoCapture(0)
  try:
    while True:
      ret, frame = cap.read()
      #frame = cv2.resize(frame, (320, 240))
      
      _, img_encoded = cv2.imencode('.jpg', frame,[cv2.IMWRITE_JPEG_QUALITY, 40])
      img_bytes = img_encoded.tobytes()
      all_socket.camera_socket.sendall(struct.pack(">L", len(img_bytes)))
      all_socket.camera_socket.sendall(img_bytes)
      #time.sleep(0.05)
  except Exception as e:
    print(f'video erro: {e}')
  finally:
    cap.release()
    all_socket.camera_socket.close()
"""

def camera_send():
  camera = cv2.VideoCapture(0)
  try:
    while True:
        
      ret, frame = camera.read()
      encode_param = [int(cv2.IMWRITE_JPEG_QUALITY),20]
      _, img_data = cv2.imencode('.jpg', frame, encode_param)
    

      all_socket.camera_socket.sendall(struct.pack(">L", len(img_data)))
      all_socket.camera_socket.sendall(img_data)
    
    
  except Exception as e:
    print(f'video erro: {e}')
  finally:
    camera.release()
    all_socket.camera_socket.close()



